In [31]:
# import library
library(RCy3)
library(igraph)
# import utility
source("../../utility/import.R")
# first, delete existing windows to save memory:
deleteAllWindows(CytoscapeConnection())
# create graph class
g <- new ('graphNEL', edgemode='directed')
edgeDataDefaults(g, attr = "edgeType") <- "undefined"
attr(edgeDataDefaults(g, attr = "edgeType"), "class") <- "STRING"
# Load Data
gal.matrix <- sifDataToMatrix('../sampleData/galFiltered.sif')
# Get NodesVec
gal.table.nodevec <- unique(c(gal.matrix[,1], gal.matrix[,3]))
# add nodes to graph
for(node in gal.table.nodevec){
g <- graph::addNode(node, g)
}
# get EdgeList and type
gal.table.fromvec <- gal.matrix[,1]
gal.table.type <- gal.matrix[,2]
gal.table.tovec <- gal.matrix[,3]
for (index in 1:length(gal.table.fromvec)){
g <- graph::addEdge (gal.table.fromvec[[index]] ,gal.table.tovec[[index]], g)
edgeData(g, gal.table.fromvec[[index]] ,gal.table.tovec[[index]], "edgeType") <- gal.table.type[[index]]
}
# show it in cytescape
cw <- CytoscapeWindow('vignette', graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')
In [32]:
# Select edge by selecting edge directly
# The name format is "geneA (relation) geneB".
selectEdges(cw, paste(gal.table.fromvec[[1]], " (",gal.table.type[[1]], ") ",gal.table.tovec[[1]], sep=""))
# The following code is for showing the result network image.
file.name <- paste (getwd (), 'resultImage' , 'showImageSelectOneEdge' , sep= '/' )
image.type <- 'png'
resource.uri <- paste(cw@uri,
pluginVersion(cw), "networks", as.character(cw@window.id),
paste0("views/first.", image.type),
sep="/")
request.res <- GET(resource.uri, write_disk(paste0(file.name,".", image.type), overwrite = TRUE))
In [33]:
# Select edges by attribution.
vec = c()
for (index in 1:length(gal.table.fromvec)){
if(gal.table.type[[index]] == 'pp'){
vec = c(vec, paste(gal.table.fromvec[[index]], " (",gal.table.type[[index]], ") ", gal.table.tovec[[index]],sep=""))
}
}
selectEdges (cw, vec)
# The following code is for showing the result network image.
file.name <- paste (getwd (), 'resultImage' ,'showImageSelectEdgeByAttribution' , sep= '/' )
image.type <- 'png'
resource.uri <- paste(cw@uri,
pluginVersion(cw), "networks", as.character(cw@window.id),
paste0("views/first.", image.type),
sep="/")
request.res <- GET(resource.uri, write_disk(paste0(file.name,".", image.type), overwrite = TRUE))
In [37]:
# select node by its name
selectNodes(cw, "YKR026C")
# The following code is for showing the result network image.
file.name <- paste (getwd(), 'resultImage' , 'showImageSelectOneNode' , sep= '/' )
image.type <- 'png'
resource.uri <- paste(cw@uri,
pluginVersion(cw), "networks", as.character(cw@window.id),
paste0("views/first.", image.type),
sep="/")
request.res <- GET(resource.uri, write_disk(paste0(file.name,".", image.type), overwrite = TRUE))
In [38]:
# get attributes data
gal.node.attrs <- read.table('../sampleData/galFiltered_node.attrs',stringsAsFactors=FALSE, skip=1)
head(gal.node.attrs)
In [39]:
vac = c()
for (index in 1:length(gal.node.attrs)){
if(gal.node.attrs[[index,3]] == 1){
vec = c(vec, gal.node.attrs[[index,1]])
}
}
# select Nodes by attribution
selectNodes(cw, vec)
# The following code is for showing the result network image.
file.name <- paste (getwd (), 'resultImage' , 'showImageSelectNodesByAttribution' , sep= '/' )
image.type <- 'png'
resource.uri <- paste(cw@uri,
pluginVersion(cw), "networks", as.character(cw@window.id),
paste0("views/first.", image.type),
sep="/")
request.res <- GET(resource.uri, write_disk(paste0(file.name,".", image.type), overwrite = TRUE))
In [27]:
# Hide selected nodes
hideSelectedEdges(cw)
In [28]:
# Hide selected nodes
hideSelectedNodes(cw)
In [29]:
# clear Selection
clearSelection (cw)